package io.chenhd.gateway.server;

import io.chenhd.gateway.filter.RequestLogFilter;
import io.chenhd.gateway.filter.ResponseLogFilter;
import io.chenhd.gateway.outbound.netty4.NettyHttpInboundHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;

public class NettyChannelInitializer extends ChannelInitializer<SocketChannel> {

    public NettyChannelInitializer() {
    }

    @Override
    public void initChannel(SocketChannel ch) {
        ChannelPipeline p = ch.pipeline();
        p.addLast(new HttpServerCodec());
        p.addLast(new HttpObjectAggregator(1024 * 1024));
        p.addLast(new RequestLogFilter());
        p.addLast(new ResponseLogFilter());
//        p.addLast(new HttpInboundHandler(this.proxyServer));
//        p.addLast(new OkhttpHandler();
        p.addLast(new NettyHttpInboundHandler());
    }
}
